package com.redwood.report.net;

import android.app.Activity;

import com.redwood.report.common.Constant;
import com.redwood.report.entity.ServiceResult;

import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

/**
 * 接口类
 * 苏鹏
 * 2016/07/04
 */
public class Api {
   //status??
    /**
     * 登录接口
     */
    public static void login(Activity context, String username, String psd,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("username", username);
        map.put("psd",psd);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/User/Login", new JSONObject(map), null, netCallBack, rspCls);

    }

    /***
     * 实时机台监控
     * @param context
     * @param pageSize
     * @param pageNow
     * @param day
     * @param netCallBack
     * @param rspCls
     */
    public static void jiankongList(Activity context, int pageSize, int pageNow,String day,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("pageSize", pageSize);
        map.put("pageNow",pageNow);
        map.put("day",day);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Report/jiankongList", new JSONObject(map), "数据加载中..", netCallBack, rspCls);

    }


    /***
     * 机台实时详细页面接口
     * @param context
     * @param bianhao
     * @param day
     * @param netCallBack
     * @param rspCls
     */
    public static void jtrecord(Activity context, String bianhao, String day,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("bianhao", bianhao);
        map.put("day",day);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Report/jtrecord", new JSONObject(map), "数据加载中..", netCallBack, rspCls);

    }
    /***
     * 获取某一日机器的监控日志
     * @param context
     * @param day
     * @param netCallBack
     * @param rspCls
     */
    public static void jtrecordAll(Activity context, String day,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("day",day);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Report/jtrecordAll", new JSONObject(map), "数据加载中..", netCallBack, rspCls);
    }
    /***
     * 报表统计分析
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void tongjiFenxi(Activity context, String startTimer,String endTimer,String year,String type,String dayType,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("startTimer",startTimer);
        map.put("endTimer",endTimer);
        map.put("year",year);
        map.put("type",type);
        map.put("dayType",dayType);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Report/tongjiFenxi", new JSONObject(map), "数据加载中..", netCallBack, rspCls);
    }






    /**
     * 入库
     * @param context
     * @param barcode 条码
     * @param position  仓位条码
     * @param netCallBack
     * @param rspCls
     */
    public static void storageIn(Activity context, String barcode, String position,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        map.put("position",position);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/In", new JSONObject(map), null, netCallBack, rspCls);

    }



    /**
     * 查询派工单信息
     * @param context
     * @param paigongdan 派工单条码
     * @param netCallBack
     * @param rspCls
     */
    public static void searchPaigong(Activity context, String paigongdan,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("paigongdan", paigongdan);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/PaiGong", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 出库
     * @param context
     * @param barcode 条码
     * @param paigonganId  派工单条码 其他出库就写""
     * @param netCallBack
     * @param rspCls
     */
    public static void storageOut(Activity context, String barcode, String paigonganId,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("barcode", barcode);
        map.put("paigonganId",paigonganId);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Storage/Out", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 查询报修
     */
    public static void baoXiuSearch(Activity context, String status,boolean aboutMe, int pageIndex,int pageSize,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("status", status);//状态（10.未受理，20.已受理，30.已完成，40.撤销）
        map.put("pageIndex",pageIndex);
        map.put("pageSize",pageSize);
        map.put("aboutMe",aboutMe);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getList", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 查询删除列表
     * @param context
     * @param pageIndex
     * @param pageSize
     * @param netCallBack
     * @param rspCls
     */
    public static void getdelDetail(Activity context, int pageIndex,int pageSize,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("pageIndex",pageIndex);
        map.put("pageSize",pageSize);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getDelList", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 获取设备列表
     */
    public static void machine(Activity context,String key,int pageIndex, int pageSize,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("key",key);
        map.put("pageIndex", pageIndex);
        map.put("pageSize",pageSize);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Machine/machine", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 根据设备编号查询
     */
    public static void machineGetInfo(Activity context,String macid,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("macid",macid);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/Machine/getInfo", new JSONObject(map), "查询设备中..", netCallBack, rspCls);

    }

    /**
     * 添加报修
     */
    public static void baoxiuAdd(Activity context,String macid,String mtncContent,String img,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("macid",macid);
        map.put("mtncContent",mtncContent);
        map.put("img",img);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/Add", new JSONObject(map), null, netCallBack, rspCls);

    }


    /**
     * 查询报修详细
     * wxid 报修ID
     */
    public static void baoXiuDetail(Activity context, String wxid,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("wxid", wxid);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getInfo", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 更新维修单状态
     * wxid 报修ID
     * context 更新描述
     * 状态（cx.撤销，sl.受理，th.退回，sc.删除，hf.恢复，jh.激活）
     */
    public static void updateStatus(Activity context, String wxid,String status,String contextt,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("wxid", wxid);
        map.put("status",status);
        map.put("context",contextt);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/updateStatus", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 新增维修明细
     * wxid 报修ID
     * kind 类型（10.报修补充,20.维修说明,70.结案）
     */
    public static void addWXMingXi(Activity context, String wxid,String kind,String wxContent,String img,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("wxid", wxid);
        map.put("kind",kind);
        map.put("wxContent",wxContent);
        map.put("img",img);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWXDetail/Add", new JSONObject(map), null, netCallBack, rspCls);

    }
    /**
     * 查询维修记录
     * wxid 报修ID
     */
    public static void wXMingXiList(Activity context, String wxid,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("wxid", wxid);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWXDetail/getList", new JSONObject(map), null, netCallBack, rspCls);

    }

    /**
     * 根据关键词查询列表
     * key 关键词
     */
    public static void getListByKey(Activity context, boolean aboutMe,String key,int pageIndex,int pageSize,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
        Map map = new HashMap();
        map.put("aboutMe",aboutMe);
        map.put("key", key);
        map.put("pageIndex",pageIndex);
        map.put("pageSize",pageSize);
        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getListByKey", new JSONObject(map), null, netCallBack, rspCls);

    }


//    /**
//     * 维修人员查询
//     * status 未处理 处理中 已处理
//     */
//    public static void weixiuSearch(Activity context, String status,int pageIndex,int pageSize,boolean aboutMe,NetUtils.NetCallBack<ServiceResult> netCallBack, Type rspCls) {
//        Map map = new HashMap();
//        map.put("status", status);
//        map.put("pageIndex", pageIndex);
//        map.put("pageSize", pageSize);
//        map.put("aboutMe", aboutMe);
//        NetUtils.post(context, Constant.getBaseUrl() + "/api/MachineWX/getListByModify", new JSONObject(map), null, netCallBack, rspCls);
//
//    }



    /**
     * 更新
     *
     * @param context
     * @param netCallBack
     * @param rspCls
     */
    public static void checkUpdate(Activity context, final NetUtils.NetCallBack<ServiceResult> netCallBack, Class<?> rspCls) {
        Map<String,Object> map=new HashMap<String,Object>();
        NetUtils.post(context, Constant.getBaseUrl() + "/api/System/CheckUpdate",  new JSONObject(map), null, netCallBack, rspCls);
    }
}
